﻿
$(document).ready(function () {

    var id = $('#Id').val();

    var $dialog = $('<div id="dialog-confirm"> </div>')
    		.html('<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>The project will be deleted and cannot be recovered. Are you sure?</p>')
    		.dialog({
    		    autoOpen: false,
    		    title: 'Delete Project?'
    		});

    $('#dialog-confirm').dialog({
        resizable: false,
        height: 240,
        modal: true,
        buttons: {
            "Delete": function () {
                $.post("/Project" + "/DeleteProject",
                         {
                             id: id
                         },
                       function (result) {
                           if (result.error == true) {
                               $(".ui-state-error").show();
                               $(".ui-state-error").html(result.html);
                           }
                           else {
                               window.location = result.href;
                           }
                       }
                );

                $(this).dialog("close");
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });

    $('#delete-project').click(function () {
        $dialog.dialog('open');

        return false;
    });

    var projectId = $('#projectId').val();
    $('#volunteerBtn').click(function () {
       
        
        $.post("/Project" + "/JoinProject",
                         {
                             roleid: 1,
                             projectId: projectId
                         },
                       function (result) {

                       }
                );
    });

    $('#staffBtn').click(function () {


        $.post("/Project" + "/JoinProject",
                         {
                             roleid: 2,
                             projectId: projectId
                         },
                       function (result) {

                       }
                );
     });

});




$(function () {
    var dates = $("#StartDate, #EndDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 3,
        onSelect: function (selectedDate) {
            var option = this.id == "StartDate" ? "minDate" : "maxDate",
					instance = $(this).data("datepicker"),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings);
            dates.not(this).datepicker("option", option, date);
        }
    });
});


function onProjectFollow() {
 
    var argv = onProjectFollow.arguments;
    var projectId = argv[0];

    var stateElement = "#follow-state-" + projectId;
    var projectState = $(stateElement).text();

    $.post("/" + "Project" + "/FollowProject",
               {
                   projectId: projectId,
                   userCan: projectState
               },

               function (result) {

                 
                    $(stateElement).text(result.html);
                    $(stateElement).effect("highlight", {}, 4000);
               }

         );
      }


   
  
